<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="userId"
        label="学号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建日期"
        width="180px">
      </el-table-column>
      <el-table-column
        prop="state"
        label="登记状态">
      </el-table-column>
      <el-table-column
        v-if="false"
        prop="clockId">
      </el-table-column>

      <el-table-column
        fixed="right"
        label="操作"
        align="center">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="primary" icon="el-icon-toilet-paper" size="mini">登记</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      page-size="5"
      :total="total"
      @current-change="page">
    </el-pagination>
  </div>
</template>

<script>
import {toDate} from "element-ui/src/utils/date-util";

export default {
  created:function (){
    const _this = this;
    axios.get('http://localhost:1234/clockedRecord/1/5/'+ this.Global.userId +'').then(function (resp){
      console.log(resp);
      _this.total = resp.data[0].num;
      _this.tableData = resp.data;
    })
  },
  // watch:{
  //   $route(to,from){
  //     if(to.path=="/clockHistory"){
  //       const _this = this;
  //       axios.get('http://localhost:1234/clockedRecord/1/5/'+ this.Global.userId +'').then(function (resp){
  //         _this.total = resp.data[0].num;
  //         _this.tableData = resp.data;
  //       })
  //     }
  //   }
  // },
  methods: {
    handleClick(row) {
      this.Global.clockId = row.clockId;
      this.$router.push('/clock');
    },
    page(currentPage){
      const _this = this;
      axios.get('http://localhost:1234/clockedRecord/'+ currentPage +'/5/'+ this.Global.userId +'').then(function (resp){
        console.log(resp);
        _this.tableData = resp.data;
      })
    }
  },
  data() {
    return {
      total: '',
      tableData: null,
      value: true,
      sid: ''
    }
  },
}
</script>
